<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:snbench="http://www.cs.bu.edu/snbench/WP-SNBENCH-20050712" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:variable name="title">
		<xsl:choose>
			<xsl:when test="/snbench:sxelist"> SXE list
				<xsl:value-of select="/snbench:sxelist/@id"/> </xsl:when>
			<xsl:when test="/snbench:sd"> Service Dispatcher
				<xsl:value-of select="/snbench:sd/@id"/> </xsl:when>
			<xsl:when test="/snbench:sdsteplist"> Service Dispatcher - Deployed
				Programs
				<xsl:value-of select="/snbench:sd/@id"/> </xsl:when>
			<xsl:when test="/snbench:sdstepprogram"> Service Dispatcher - Deployed
				Program
				<xsl:value-of select="/snbench:sd/@id"/> </xsl:when>
			<xsl:when test="/snbench:rm"> Resource Manager
				<xsl:value-of select="/snbench:rm/@id"/> </xsl:when>
			<xsl:when test="/snbench:sxe"> SXE
				<xsl:value-of select="/snbench:sxe/@id"/> </xsl:when>
			<xsl:when test="/snbench:step"> STEP graph
				<xsl:value-of select="/snbench:step/@id"/> </xsl:when>
			<xsl:when test="/snbench:node"> STEP node
				<xsl:value-of select="/snbench:node/@id"/> index </xsl:when>
			<xsl:when test="/snbench:sensorDevices"> Sensor Array</xsl:when>
			<xsl:when test="/snbench:rmSensorList">Sensors active in the Sensorium</xsl:when>			
			<xsl:when test="/snbench:sensorTypes">Sensor Device Types</xsl:when>
			<xsl:when test="/snbench:device"> <xsl:value-of select="/snbench:device/@type"/> Sensor:
				<xsl:value-of select="/snbench:device/@id"/> </xsl:when>
			<xsl:when test="/snbench:storageData">
				Local Storage
			</xsl:when>
			<xsl:when test="/snbench:applet">
				Step Graph Viewer
			</xsl:when>
				
			<xsl:otherwise> STEP node
				<xsl:value-of select="/*/@id"/> metadata </xsl:otherwise>
		</xsl:choose>
    </xsl:variable>
    <xsl:template match="/">
        <html>
            <head>
                <title>
                    <xsl:copy-of select="$title"/>
                </title>
                <link href="/snbench/markup/sxe20050712.css" rel="stylesheet" title="Default"/>
            </head>
            <body bgcolor="#FFFFFF">
                <h1>
                    <xsl:copy-of select="$title"/>
				</h1>
				
                <xsl:apply-templates/>
				
                <div id="footer">
                    <img class="logo" src="/snbench/markup/logo.png"/>
		  This interface is raw XML that has been styled for easy viewing on your web browser.
          For more information on snBench and SXEs, please see                    
		  <a href="http://csr.bu.edu/snbench/">the snBench homepage</a>
.                </div>
                <div id="bottom"/>
            </body>
        </html>
    </xsl:template>
	
    <xsl:template match="snbench:sensor">
        <dl>
            <dt>Name</dt>
            <dd>
                <xsl:value-of select="snbench:sensor/snbench:name"/>
            </dd>
            <dt>State</dt>
            <dd>
                <xsl:value-of select="snbench:sensor/snbench:state"/>
            </dd>
        </dl>
    </xsl:template>
    
	<!-- comments -->
	<xsl:template name="backtosxeroot">
		<div class="backlink">
			<a href="/snbench/sxe/">Return to root SXE resource page</a>
		</div>
	</xsl:template>
	
	<xsl:template name="jumpnavserver">
		<div class="jumpto">
        <ul><li><a href="/snbench/rm/">Resource Manager (Resource oriented view)</a></li>
			<ul>
				<li>[<a href="/snbench/rm/sxe/">View all connected SXEs</a>]</li>
				<li>[<a href="/snbench/rm/sensors/">View all connected Sensors</a>]</li>
			</ul>
			<li><a href="/snbench/sd/">Service Dispatcher (Program oriented view)</a></li>
        </ul>
        </div>
	</xsl:template>

	<xsl:template name="jumpnavsxe">
		<div class="jumpto">
        <ul><li>[<a href="/snbench/sxe/">SXE Root</a>]</li>
			<li>[<a href="/snbench/sxe/node/">STEP Graph</a>]</li>
			<li>[<a href="/snbench/sxe/sensor/">Sensors</a>]</li>
        </ul>
        </div>
	</xsl:template>
		<!-- end -->

	<xsl:template name="poststeptosxe">
	<center>
		<table BORDER="0">
			<TR>
				<td>Select a STEP XML file to upload:</td>
			</TR>
			<TR>
				<td>
				<form action="/snbench/sxe/node/" method="post" enctype="multipart/form-data">
					<INPUT type="file" name="program" enctype="snbench/program"/>
					<BR/>
					<INPUT type="submit" value="POST"/> 
					<INPUT type="reset"/>
				</form>
				</td>
			</TR>
		</table>
	</center>
	</xsl:template>

	<xsl:template name="poststeptosd">
	<center>
		<table BORDER="0">
			<TR>
				<td>Select a STEP XML file to upload:</td>
			</TR>
			<TR>
				<td>
				<form action="/snbench/sd/" method="post" enctype="multipart/form-data">
					<INPUT type="file" name="program" enctype="snbench/program"/>
					<BR/>
					<INPUT type="submit" value="POST"/> 
					<INPUT type="reset"/>
				</form>
				</td>
			</TR>
		</table>
	</center>
	</xsl:template>
		
	<xsl:template match="/*">
        <xsl:choose>
<!-- sxe root resource -->			
            <xsl:when test="/snbench:sxe">
				Available resources: <xsl:value-of select="/snbench:sxe/@resources"/>
				<h2>Browse this SXE's ...</h2>
				<ul>
                    <li>
                        <a href="{/snbench:sxe/snbench:step/@href}">
							<i>
                               Live STEP nodes (list)<br/>
								<!--<small>(<xsl:value-of select="/snbench:sxe/snbench:step/@id"/></small>-->
                            </i>
                        </a>
						<ul>
						<li>
							<small><a href="/snbench/sxe/graph/">... as XML</a></small>
						</li>
						<li>
							<small><a href="/snbench/sxe/graphview/">... as an interavtive graph (requires Java plug-in 1.5)</a></small>
						</li>						
						</ul>
				    </li>
                    <li>
                        <a href="/snbench/sxe/sensor/">Sensor Devices</a>
                    </li>
                    <li>
                        <a href="/snbench/sxe/storage/">Local Storage</a>
                    </li>

                </ul>
            </xsl:when>
            
<!-- Graphical applet for viewing the STEP on an SXE resource -->
    <xsl:when test="/snbench:applet">         
	<object
	    classid = "clsid:CAFEEFAC-0015-0000-0009-ABCDEFFEDCBA"
	    codebase = "http://java.sun.com/update/1.5.0/jinstall-1_5_0_09-windows-i586.cab#Version=5,0,90,3"
	    WIDTH = "100%" HEIGHT = "400" >
	    <PARAM NAME = "CODE" VALUE = "STEPVisualizer.Visualizer.class" />
	    <PARAM NAME = "ARCHIVE" VALUE = "snbench.jar,jgrapht.jar,jgraphlayout.jar" />
	    <param name = "type" value = "application/x-java-applet;jpi-version=1.5.0_09"/>
	    <param name = "scriptable" value = "false"/>
	 	<PARAM NAME="cache_option" VALUE="false"/>
	 	<PARAM NAME="SXEHOST" VALUE="{@host}"/>
	 	<comment>
		<embed
	            CODE = "STEPVisualizer.Visualizer.class" 
	            type="application/x-java-applet"
	            ARCHIVE = "snbench.jar,jgraphlayout.jar,jgrapht.jar" 
	            WIDTH = "100%" 
	            HEIGHT = "400" 
		    scriptable = "false" 
		    cache_option = "false" 
			SXEHOST = "{@host}" 
		    pluginspage="http://java.sun.com/javase/downloads/ea.jsp">
		    <noembed>
	            alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
		Your browser is completely ignoring the &lt;APPLET&gt; tag!
	            </noembed>
		</embed>
	    </comment>
	</object>
    </xsl:when>
            
<!-- Service Dispatcher (SD) root resource -->
            <xsl:when test="/snbench:sd">
				<dl>
                    <dt>Up-time:<xsl:value-of select="@uptime"/></dt>
                </dl>
                <dl>
                    <dt>STEP Programs</dt>
                </dl>
                <ul>
                    <xsl:choose>
                        <xsl:when test="/snbench:sd/snbench:steplist/snbench:step">
                            <xsl:for-each select="/snbench:sd/snbench:steplist/snbench:step">
                                <li>
                                    <a href="{@href}">
                                        <i>
                                            <xsl:value-of select="@program_id"/>
                                        </i>
										   [<xsl:value-of select="@state"/>]
                                    </a>
                                </li>
                            </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise>
							No STEP programs are registered at present.</xsl:otherwise>
                    </xsl:choose>
                </ul>
                <xsl:call-template name="jumpnavserver">
				</xsl:call-template>
            </xsl:when>
<!-- Service Dispatcher (SD) Program List resource -->
            <xsl:when test="/snbench:sdsteplist">
                <dl>
                    <dt>STEP Programs</dt>
                </dl>
                <ul>
                    <xsl:choose>
                        <xsl:when test="/snbench:sdsteplist/snbench:steplist">
                            <xsl:for-each select="/snbench:sdsteplist/snbench:steplist/snbench:step">
                                <li>
                                    <a href="{@href}">
                                        <i>
                                            <xsl:value-of select="@program_id"/>
                                        </i>
										    [<xsl:value-of select="@state"/>]
                                    </a>
                                </li>
                            </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise>				 No STEP programs are registered at present.</xsl:otherwise>
                    </xsl:choose>
                </ul>
                <xsl:call-template name="jumpnavserver">
				</xsl:call-template>				
            </xsl:when>
<!-- Service Dispatcher (SD) SINGLE deployed program view  -->
            <xsl:when test="/snbench:sdstepprogram">
				<dl>
                    <dt>
STEP Program:                        <xsl:value-of select="/snbench:sdstepprogram/snbench:step/@program_id"/>
                    </dt>
                </dl>
nodes (<xsl:value-of select="/snbench:sdstepprogram/snbench:step/@size"/>)
				<table border="1">
					<tr>
						<td colspan="2">
						STEP Nodes
						</td>
					</tr>
					<tr>
						<th>ID</th>						
						<th>Type</th>
					</tr>
                    <xsl:for-each select="/snbench:sdstepprogram/snbench:step/snbench:*">
						<tr>
							<td>
							     <a href="{@href}">
								 <xsl:value-of select="@id"/>
								 </a>
							</td>
							<td>
								<xsl:value-of select="name()"/>
							</td>
						</tr>
                    </xsl:for-each>
				</table>
                <xsl:call-template name="jumpnavserver">
				</xsl:call-template>
				</xsl:when>
<!-- Resource Manager (RM) root resource -->
            <xsl:when test="/snbench:rm">
                <xsl:call-template name="jumpnavserver">
				</xsl:call-template>
            </xsl:when>
<!-- RM SXEList root resource -->
            <xsl:when test="/snbench:sxelist">
                <dl>
                    <dt>SXEs</dt>
                </dl>
                <ul>
                    <xsl:choose>
                        <xsl:when test="/snbench:sxelist/snbench:sxe">
                        <table border="1">
							<tr>
								<th>ID</th>
								<th>resources</th>
								<th>sensors</th>
								<th>last report</th>
							</tr>
							<xsl:for-each select="/snbench:sxelist/snbench:sxe">
                            <tr>
								<td><a href="{@href}">
						            [<xsl:value-of select="@id"/>]
                                    </a>
								</td>
								<td>
									<xsl:value-of select="@resources"/>
								</td>
								<td>
									yes
								</td>
								<td>
									<xsl:value-of select="@lastreport"/>
								</td>
							</tr>
                            </xsl:for-each>
						</table>
                        </xsl:when>
                        <xsl:otherwise>No SXEs registered at present.</xsl:otherwise>
                    </xsl:choose>
                </ul>
                <xsl:call-template name="jumpnavserver">
				</xsl:call-template>                
	            </xsl:when>
<!-- sxe sensor index resource -->
            <xsl:when test="/snbench:rmSensorList">
                <ul>
                <xsl:choose>
                    <xsl:when test="/snbench:rmSensorList/snbench:device">
                        <table border="1">
							<tr>
								<th>ID</th>
								<th>Name</th>
								<th>Type</th>
								<th>State</th>
							</tr>
					
                    <xsl:for-each select="/snbench:rmSensorList/snbench:device">
							<tr>
								<td>
		                            <a href="/snbench/sxe/sensor/{@type}/{@id}/">
Sensor                              <xsl:value-of select="@id"/>
									</a>
								</td>
								<td>
									<xsl:choose>
										<xsl:when test="snbench:name">
											<xsl:value-of select="snbench:name"/>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select="@id"/>
										</xsl:otherwise>
									</xsl:choose>									
								</td>
								<td>
									<xsl:value-of select="@type"/>
								</td>
								<td>
									<xsl:value-of select="@state"/>
								</td>
						</tr>
					</xsl:for-each>
					</table>
					</xsl:when>
					<xsl:otherwise>
					No Sensors registered at present.	
					</xsl:otherwise>
					</xsl:choose>
                </ul>
                <xsl:call-template name="jumpnavserver">
				</xsl:call-template>
            </xsl:when>
            <xsl:when test="/snbench:sensorDevices">
                <ul>
                    <xsl:for-each select="/snbench:sensorDevices/snbench:device">
                        <li>
                            <a href="/snbench/sxe/sensor/{@type}/{@id}/">
Sensor                                <xsl:value-of select="@id"/>
                            </a>
                            <dl>
                                <dt>Name</dt>
                                <dd>
                        <xsl:choose>
                            <xsl:when test="snbench:name">
						        <xsl:value-of select="snbench:name"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="@id"/>
                            </xsl:otherwise>
                        </xsl:choose>

                                </dd>
                                <dt>Type</dt>
                                <dd>
                                    <xsl:value-of select="@type"/>
                                </dd>
<!--
			    <xsl:choose>
			      <xsl:when test="snbench:deviceFormats/snbench:videoFormat">
	                <dt>Type</dt>
	                <dd>Video</dd>
				  </xsl:when>
			      <xsl:when test="snbench:deviceFormats/snbench:audioFormat">
	                <dt>Type</dt>
	                <dd>Audio</dd>
				  </xsl:when>
				</xsl:choose>
-->
                                <dt>State</dt>
                                <dd>
                                    <xsl:value-of select="@state"/>
                                </dd>
                            </dl>
                        </li>
                    </xsl:for-each>
                </ul>
				<xsl:call-template name="backtosxeroot"/>
            </xsl:when>

	<!-- sxe sensor index resource -->
            <xsl:when test="/snbench:sensorTypes">
                <ul>
                    <xsl:for-each select="/snbench:sensorTypes/snbench:*">
                        <li>
                            <h2>
                                <a href="/snbench/sxe/sensor/{@id}/">
                                    <xsl:value-of select="@id"/>
Sensors                                </a>
                            </h2>
                            <dl>
                                <dt>Quantity</dt>
                                <dd>
                                    <xsl:value-of select="snbench:count"/>
                                </dd>
                            </dl>
                        </li>
                    </xsl:for-each>
                </ul>
				<xsl:call-template name="backtosxeroot"/>
			</xsl:when>
<!-- sxe sensor resource -->
            <xsl:when test="/snbench:device">
                <dl>
                    <dt>Name</dt>
                    <dd>
                        <xsl:value-of select="snbench:name"/>
                    </dd>
                    <dt>State</dt>
                    <dd>
                        <xsl:value-of select="@state"/>
                    </dd>
                    <dt>Data</dt>
					<dd>
						<a href="data/">Data from this sensor</a>
                    </dd>
                    <xsl:if test="snbench:location">
                        <dt>Location</dt>
                        <dd>
                            <xsl:value-of select="snbench:location"/>
                        </dd>
                    </xsl:if>
                    <dt>Supports</dt>
                    <ul>
                        <xsl:for-each select="/snbench:device/snbench:deviceFormats/snbench:videoFormat">
                            <li>
Video Format                                <dl>
                                    <dt>Encoding</dt>
                                    <dd>
                                        <xsl:value-of select="snbench:encoding"/>
                                    </dd>
                                    <dt>Max Length</dt>
                                    <dd>
                                        <xsl:value-of select="snbench:maxlength"/>
                                    </dd>
                                    <dt>Width</dt>
                                    <dd>
                                        <xsl:value-of select="snbench:resolution/snbench:width"/>
                                    </dd>
                                    <dt>Height</dt>
                                    <dd>
                                        <xsl:value-of select="snbench:resolution/snbench:height"/>
                                    </dd>
                                </dl>
                            </li>
                        </xsl:for-each>
                        <xsl:for-each select="/snbench:sensor/snbench:deviceFormats/snbench:audioFormat">
                            <li>
Audio Format                                <dl>
                                    <dt>Encoding</dt>
                                    <dd>
                                        <xsl:value-of select="snbench:encoding"/>
                                    </dd>
                                    <dt>Channels</dt>
                                    <dd>
                                        <xsl:value-of select="snbench:channels"/>
                                    </dd>
                                    <dt>Sample Rate</dt>
                                    <dd>
                                        <xsl:value-of select="snbench:samplerate"/>
                                    </dd>
                                    <dt>Big Endian</dt>
                                    <dd>
                                        <xsl:value-of select="snbench:bigendian"/>
                                    </dd>
                                </dl>
                            </li>
                        </xsl:for-each>
                        <xsl:for-each select="/snbench:sensor/snbench:deviceFormats/snbench:tempFormat">
                            <li>
Temperature Format                                <dl>
                                    <dt>Unit</dt>
                                    <dd>
                                        <xsl:value-of select="snbench:unit"/>
                                    </dd>
                                </dl>
                            </li>
                        </xsl:for-each>
                    </ul>
                </dl>
				<xsl:call-template name="backtosxeroot"/>
			</xsl:when>
<!-- sxe graph resource -->
            <xsl:when test="/snbench:step">
                <ul>
                    <xsl:for-each select="/snbench:step/snbench:*">
                        <li>
                            <a href="{@href}">
                                <xsl:value-of select="name()"/>
&quot;                                <i>
                                    <xsl:value-of select="@id"/>
                                </i>
                            </a>
&quot; :                            <a href="{@href}info">(Metadata)</a>
/                            <a href="{@href}data">(Value)</a>
                        </li>
                    </xsl:for-each>
                </ul>
				<xsl:call-template name="backtosxeroot"/>
			</xsl:when>
			<!-- STORAGE STYLE SHEET -->
      <!-- sxe sensor index resource -->
      <xsl:when test="/snbench:storageData">
        <h2>Cached snObject Hash Table</h2>
<!--	<B>Using Storage Server:</B> -->
	<table border="1">
        <TR><TD><b>Key</b></TD></TR>
          <xsl:for-each select="/snbench:storageData/snbench:*">
              <TR>
                 <TD>
                 	<a href="{@href}">
	                 <xsl:value-of select="@key"/>
	                </a>
                 </TD>
              </TR>
          </xsl:for-each>
        </table>
        <FORM action="/snbench/sxe/storage/">
            key: <INPUT name="key"/><BR/>
            value: <INPUT name="value"/> <BR/>
        <select name="action">
          <OPTION>put</OPTION>
          <OPTION>remove</OPTION>
          <OPTION>get</OPTION>
        </select><BR/>
        <INPUT type="submit" value="Submit"/>
        </FORM>
		<xsl:call-template name="backtosxeroot"/>
      </xsl:when>
<!---END STORAGE STYLE SHEET -->

			
<!-- sxe node top resource -->
            <xsl:when test="/snbench:node">
                <ul>
                    <li>
                        <a href="{snbench:info/@href}">Metadata</a>
                    </li>
                    <li>
                        <a href="{snbench:data/@href}">Current Value (if any)</a>
                    </li>
                </ul>
				<xsl:call-template name="backtosxeroot"/>
			</xsl:when>
<!-- sxe info resource -->
            <xsl:otherwise>
                <dl>
                    <dt>Node Type</dt>
                    <dd>
                        <xsl:value-of select="name()"/>
                    </dd>
                    <xsl:if test="/snbench:level_trigger">
                        <dt>State</dt>
                        <dd>
                            <xsl:value-of select="./snbench:state"/>
                        </dd>
                    </xsl:if>
                    <xsl:if test="/snbench:socket">Socket...</xsl:if>
                    <dt>ID</dt>
                    <dd>
                        <xsl:value-of select="@id"/>
                    </dd>
                    <dt>Source Graph</dt>
                    <dd>
                        <xsl:value-of select="./snbench:source"/>
                    </dd>
                    <dt>Enabled</dt>
                    <dd>
                        <xsl:choose>
                            <xsl:when test="./snbench:enabled">true</xsl:when>
                            <xsl:otherwise>false</xsl:otherwise>
                        </xsl:choose>
                    </dd>
                    <dt>Evaluated</dt>
                    <dd>
                        <xsl:choose>
                            <xsl:when test="./snbench:evaluated">true</xsl:when>
                            <xsl:otherwise>false</xsl:otherwise>
                        </xsl:choose>
                    </dd>
                    <dt>Wanted</dt>
                    <dd>
                        <xsl:choose>
                            <xsl:when test="./snbench:wanted">true</xsl:when>
                            <xsl:otherwise>false</xsl:otherwise>
                        </xsl:choose>
                    </dd>
                    <dt>Garbage</dt>
                    <dd>
                        <xsl:choose>
                            <xsl:when test="./snbench:garbage">
true, TTL:                                <xsl:value-of select="./snbench:garbage"/>
                            </xsl:when>
                            <xsl:otherwise>false</xsl:otherwise>
                        </xsl:choose>
                    </dd>
                    <dt>Operands</dt>
                    <dd>
                        <ul>
                            <xsl:for-each select="./snbench:operands/*">
                                <li>
                                    <span>
                                        <a href="/snbench/sxe/node/{@id}/">
Node                                            <xsl:value-of select="@id"/>
                                        </a>
                                    </span>
                                    <span>
(                                        <a href="/snbench/sxe/node/{@id}/data">value</a>
)                                    </span>
                                    <span>
(                                        <a href="/snbench/sxe/node/{@id}/info">metadata</a>
)                                    </span>
                                    <span>
Fresh:                                        <b>
                                            <xsl:value-of select="@fresh"/>
                                        </b>
                                    </span>
                                </li>
                            </xsl:for-each>
                        </ul>
                    </dd>
                    <xsl:choose>
                        <xsl:when test="./snbench:type">
                            <dt>Current Value</dt>
                            <dd>
                                <a href="data">
								(<xsl:value-of select="./snbench:type"/>)<br/>
								<iframe id="ifrm" name="ifrm" src="data" scrolling="no" width="200" height="150" frameborder="2">
                                []
                                </iframe>
							    </a>
                            </dd>
                        </xsl:when>
                    </xsl:choose>
                    <dt>Operand Of</dt>
                    <dd>
                        <ul>
                            <xsl:for-each select="./snbench:operandof/*">
                                <li>
                                    <a href="/snbench/sxe/node/{@id}/">
Node                                        <xsl:value-of select="@id"/>
                                    </a>
(                                    <a href="/snbench/sxe/node/{@id}/data">value</a>
)                                </li>
                            </xsl:for-each>
                        </ul>
                    </dd>
                    <dt>Evaluation Count</dt>
                    <dd>
                        <xsl:value-of select="./snbench:evaluationcount/@value"/>
                    </dd>
                </dl>
                <div class="backlink">
                    <ul>
                        <li>
                            <a href="/snbench/sxe/node/{@id}/">Node resource</a>
                        </li>
                        <li>
                            <a href="/snbench/sxe/node/">Graph Index</a>
                        </li>
					</ul>
                </div>
				<xsl:call-template name="backtosxeroot"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
